package comprehension.cn.edu.scau.cmi.huxiantao.util;

import java.util.List;

import comprehension.cn.edu.scau.cmi.huxiantao.domain.Student;
import comprehension.cn.edu.scau.cmi.huxiantao.domain.Teacher;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

public class TableInfo {
	private int studentId;
	private String studentName;
	private String teacherId;
	private String teacherName;

	public TableInfo(int studentId, String studentName, String teacherId, String teacherName) {
		super();
		this.studentId = studentId;
		this.studentName = studentName;
		this.teacherId = teacherId;
		this.teacherName = teacherName;
	}
	
	public TableInfo( int id, String name) {
		super();
		this.studentId = id;
		this.studentName = name;
		this.teacherId = String.valueOf(id);
		this.teacherName = name;
	}

	public static ObservableList<TableInfo> transformStudentList(List<Student> students){
		ObservableList<TableInfo> tableInfos = FXCollections.observableArrayList();
		
		students.forEach(s -> {
			if(s.getTeacher()==null) {
				tableInfos.add(new TableInfo(s.getId(),s.getName(),"",""));
			}else {
				tableInfos.add(new TableInfo(s.getId(), s.getName(), 
						String.valueOf(s.getTeacher().getId()), s.getTeacher().getName()));
			}
		});
		
		return tableInfos;
	}
	
	public static ObservableList<TableInfo> transformTeacherList(List<Teacher> teachers){
		ObservableList<TableInfo> tableInfos = FXCollections.observableArrayList();
		
		teachers.forEach(t -> {
			tableInfos.add(new TableInfo(t.getId(), t.getName() ));
		});
		
		return tableInfos;
	}

	public int getStudentId() {
		return studentId;
	}

	public void setStudentId(int studentId) {
		this.studentId = studentId;
	}

	public String getStudentName() {
		return studentName;
	}

	public void setStudentName(String studentName) {
		this.studentName = studentName;
	}

	public String getTeacherId() {
		return teacherId;
	}

	public void setTeacherId(String teacherId) {
		this.teacherId = teacherId;
	}

	public String getTeacherName() {
		return teacherName;
	}

	public void setTeacherName(String teacherName) {
		this.teacherName = teacherName;
	}

}
